package com.meessiom.train.crm.product.controller;
import com.meessiom.train.crm.employee.model.Employee;
import com.meessiom.train.crm.product.model.Product;
import com.meessiom.train.crm.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/api/v1/product") //这是控制器的地址
@Slf4j
public class ProductController {


    @Autowired
    private ProductService productService;


    @GetMapping
    public List<Product> getAllProduct() {
        log.info("获得了来自客户端的获得产品列表的的请求");
        return productService.getAllProduct();
    }

    @GetMapping({"{id}"})
    public ResponseEntity<Product> getProductById(@PathVariable long id) {
        Product product = this.productService.getProductById(id);
        return ResponseEntity.ok(product);
    }

    @DeleteMapping({"{id}"})
    public ResponseEntity<HttpStatus> deleteProduct(@PathVariable long id) {
        this.productService.deleteProduct(id);
        return new ResponseEntity(HttpStatus.NO_CONTENT);


    }

}
